package com.eascs.ant.user.component;

import javax.inject.Inject;

import org.springframework.stereotype.Component;

import com.eascs.ant.user.entity.User;
import com.eascs.ant.user.service.UserService;
import com.eascs.web.sso.UserHolder;

@Component
public class SystemUserHolder {
	@Inject
	private UserService userService;

	private final ThreadLocal<com.eascs.web.sso.User> userLocal = new ThreadLocal<>();

	public void holde() {
		com.eascs.web.sso.User oldUser = UserHolder.getUser();
		User user = userService.getUserByCode("system");
		com.eascs.web.sso.User holdUser = new com.eascs.web.sso.User();
		holdUser.setAccount(user.getLoginName());
		holdUser.setCode(user.getCode());
		holdUser.setCname(user.getName());
		holdUser.setEmail(user.getEmail());
		holdUser.setPhone(user.getPhone());
		holdUser.setSuperAdministrator(true);
		UserHolder.setUser(holdUser);
		userLocal.set(oldUser);
	}

	public void rest() {
		UserHolder.setUser(userLocal.get());
	}

}
